Skip to content

Add unique-names anchor to fragments docs - #13336

Closed
atharv-sys32 wants to merge 4 commits into
apollographql:mainfrom
atharv-sys32:docs/unique-names-anchor
Closed

Add unique-names anchor to fragments docs#13336
atharv-sys32 wants to merge 4 commits into
apollographql:mainfrom
atharv-sys32:docs/unique-names-anchor

Conversation

@atharv-sys32

@atharv-sys32 atharv-sys32 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The graphql-tag library warns when duplicate fragment names are found and links to http://dev.apollodata.com/core/fragments.html#unique-names. This URL no longer resolves.

This PR adds a dedicated section with the {#unique-names} custom anchor ID to the Apollo Client fragments docs page so that the old link serves useful content instead of a 404.

Fixes #13292

Summary by CodeRabbit

  • Documentation
    • Added guidance on using unique fragment names across the application.
    • Documented the warning shown when duplicate fragment names are detected.
    • Recommended descriptive, component-scoped naming to prevent conflicts.

@atharv-sys32
atharv-sys32 requested a review from a team as a code owner July 15, 2026 19:16
@apollo-cla

Copy link
Copy Markdown

@atharv-sys32: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 94ef9f4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@apollo-librarian

apollo-librarian Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

⚠️ AI Style Review — 1 Issue Found

Summary

The documentation has been updated to align with the style guide across five sections. In 'framing-apollo-products', language was adjusted to focus on tool benefits over technical conflicts. General 'framing' now prioritizes direct address using 'you' and 'your'. For 'products-and-features', articles like 'the' were removed before standalone product names. The 'voice' section was updated to use more authoritative, active phrasing to prevent errors. Finally, under 'word-and-symbol-usage', semicolons were replaced with periods to improve clarity.

Duration: 2480ms
Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: cd2e0423-6a84-406b-9600-73f86972edde

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a “Unique fragment names” section to the fragments documentation, including the duplicate-name warning and naming guidance. Updates the changeset with a patch bump for @apollo/client and references the documentation anchor.

Changes

Fragment names documentation

Layer / File(s) Summary
Unique fragment name guidance
docs/source/data/fragments.mdx, .changeset/quiet-pans-doubt.md
Documents fragment-name uniqueness, duplicate graphql-tag warnings, component-scoped naming, and the related @apollo/client patch release metadata.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit hops through fragments bright,
Naming each one just right.
No duplicate hare will hide,
As anchors bloom from side to side.
Patch notes twitch with pure delight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding the unique-names anchor to the fragments docs.
Linked Issues check ✅ Passed The docs update adds the unique-names section and anchor needed for the legacy warning link in #13292.
Out of Scope Changes check ✅ Passed The changes stay focused on the fragments docs anchor and related release note, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/source/data/fragments.mdx`:
- Line 46: Update the duplicate-fragment explanation in the fragment
documentation to state that graphql-tag warns whenever the same fragment name is
reused, without qualifying it by different field selections. Preserve the
existing runtime-warning context and uniqueness requirement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 311dfd1c-1396-439e-9967-dc234485b79a

📥 Commits

Reviewing files that changed from the base of the PR and between 544daab and c0c2f5e.

📒 Files selected for processing (2)
  • .changeset/quiet-pans-doubt.md
  • docs/source/data/fragments.mdx

Comment thread docs/source/data/fragments.mdx Outdated

## Unique fragment names {#unique-names}

Fragment names must be unique across your entire application. If you accidentally define two fragments with the same name but different field selections, `graphql-tag` warns you about the conflict at runtime to prevent subtle bugs:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

sed -n '40,55p' docs/source/data/fragments.mdx

Repository: apollographql/apollo-client

Length of output: 1025


🏁 Script executed:

rg -n "unique across your entire application|different field selections|graphql-tag warns" -S docs/source/data/fragments.mdx . || true

Repository: apollographql/apollo-client

Length of output: 699


🏁 Script executed:

python3 - <<'PY'
from pathlib import Path
p = Path('docs/source/data/fragments.mdx')
for i, line in enumerate(p.read_text().splitlines(), 1):
    if 40 <= i <= 55:
        print(f"{i}: {line}")
PY

Repository: apollographql/apollo-client

Length of output: 1089


🌐 Web query:

graphql-tag warns same fragment name different source identical fragment definitions warning implementation fragmentSourceMap

💡 Result:

The "Warning: fragment with name X already exists" message emitted by the graphql-tag library occurs because the package enforces global uniqueness for fragment names across your application [1][2][3]. Implementation Details: The library maintains an internal state using a structure often referred to as a fragmentSourceMap (or conceptually similar tracking mechanisms in its codebase) [2]. When you define a GraphQL document using the gql template literal, the library processes the document and inspects all fragment definitions [2]. For each fragment, it tracks the mapping between the fragment name and its source code [2]. If it encounters a fragment name that has already been registered with a different source definition, it triggers a console warning [2]. Even if the fragments are logically identical, the library's internal check may treat them as collisions if their source locations or registration contexts differ, leading to the warning [2][4]. How to Disable: If you are confident that your fragment names are intentionally reused or that the warnings are false positives in your architecture, you can disable these warnings by calling the disableFragmentWarnings function provided by the graphql-tag package [1][5][3]: import { disableFragmentWarnings } from 'graphql-tag'; disableFragmentWarnings; Note that if you are using a modern Apollo Client setup, you might occasionally need to import this from @apollo/client if it is bundled as a dependency, though importing directly from graphql-tag is the standard approach [1][6]. This warning is a legacy enforcement mechanism from earlier Apollo development practices and does not typically affect the runtime functionality of your GraphQL queries [4].

Citations:


Describe duplicate fragment names without the field-selection qualifier.
graphql-tag warns whenever the same fragment name is reused, so the “but different field selections” part is misleading and can imply identical duplicates are allowed.

🧰 Tools
🪛 GitHub Check: AI Style Review

[notice] 46-46: docs/source/data/fragments.mdx#L46
Framing Apollo Products: The phrase 'prevent subtle bugs' can be framed more positively as helping the user avoid them.

Voice: Use an authoritative and encouraging tone to prescribe the best practice.

Word and Symbol Usage: Avoid semicolons; use a period to separate independent clauses for better clarity.

Suggested change
Fragment names must be unique across your entire application. If you accidentally define two fragments with the same name but different field selections, `graphql-tag` warns you about the conflict at runtime to prevent subtle bugs:
Fragment names must be unique across your entire application. If you define two fragments with the same name but different field selections, `graphql-tag` warns you about the conflict at runtime to help you avoid bugs:
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/source/data/fragments.mdx` at line 46, Update the duplicate-fragment
explanation in the fragment documentation to state that graphql-tag warns
whenever the same fragment name is reused, without qualifying it by different
field selections. Preserve the existing runtime-warning context and uniqueness
requirement.

Comment thread docs/source/data/fragments.mdx Outdated
## Unique fragment names {#unique-names}

Fragment names must be unique across your entire application. If you accidentally define two fragments with the same name but different field selections, `graphql-tag` warns you about the conflict at runtime to prevent subtle bugs:
Fragment names must be unique across your entire application. If you accidentally reuse a fragment name, `graphql-tag` warns you about the conflict at runtime to prevent subtle bugs:

@jsoref jsoref Jul 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fragment names must be unique across your entire application. If you accidentally reuse a fragment name, `graphql-tag` warns you about the conflict at runtime to prevent subtle bugs:
Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` component will warn about the conflict at runtime to prevent subtle bugs:
  1. accidentally (as called out elsewhere) achieves the wrong thing. The callers I looked at were intentionally using the same term -- they just happened to use it to mean different things which this tool doesn't like.
  2. Users (e.g., me) have no idea what graphql-tag is. I didn't write <graphql-tag>foo...</graphql-tag> or <graphql>foo...</graphql>. We just used apollo. We land here because we used apollo and it spat out an error message. graphql-tag is an implementation detail that's bleeding outward.

…s resolve

The graphql-tag library warns when duplicate fragment names are found
and links to http://dev.apollodata.com/core/fragments.html#unique-names.
This URL no longer resolves. Add a dedicated section with the {#unique-names}
custom anchor ID to the Apollo Client fragments docs page so the link
serves useful content instead of a 404.

Fixes #13292
Remove 'accidentally' - the warning is about intentional reuse,
and 'graphql-tag' is an implementation detail that users don't
need to know about.
@atharv-sys32
atharv-sys32 force-pushed the docs/unique-names-anchor branch from ccb1177 to 27a6ae5 Compare July 24, 2026 19:40

@jerelmiller jerelmiller left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple small changes. Thanks for helping move this forward!

Comment thread .changeset/quiet-pans-doubt.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a docs-only change, no need for a changeset. Appreciate it though!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the changeset file as requested.

Comment thread docs/source/data/fragments.mdx Outdated

## Unique fragment names {#unique-names}

Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` component will warn about the conflict at runtime to prevent subtle bugs:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` component will warn about the conflict at runtime to prevent subtle bugs:
Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` library will warn about the conflict at runtime to prevent subtle bugs:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use some of the AI suggestion. We tend to use present tense rather than future tense as well:

Suggested change
Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` component will warn about the conflict at runtime to prevent subtle bugs:
Fragment names must be unique across your entire application. If you reuse a fragment name, the `graphql-tag` library warns about the conflict at runtime to help prevent bugs:

@atharv-sys32 atharv-sys32 Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - now uses "library warns" with present tense and "help prevent bugs" as you suggested.

Comment thread docs/source/data/fragments.mdx Outdated
this in the docs: http://dev.apollodata.com/core/fragments.html#unique-names
```

Always use descriptive, component-scoped fragment names (like `ItemFragment` or `UserProfileFragment`) to avoid name collisions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that this is a really good practice to do, I wouldn't make it as strong as "always". Let's soften that a bit to mention it as a best practice.

Suggested change
Always use descriptive, component-scoped fragment names (like `ItemFragment` or `UserProfileFragment`) to avoid name collisions.
As a best practice, use descriptive, component-scoped fragment names (like `ItemFragment` or `UserProfileFragment`) to avoid name collisions.

@atharv-sys32 atharv-sys32 Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - changed to "As a best practice, use" to soften it.

- Use 'library' instead of 'component' for graphql-tag
- Use present tense 'warns' instead of future tense
- Use 'help prevent bugs' instead of 'prevent subtle bugs'
- Soften 'Always use' to 'As a best practice, use'
- Remove unnecessary changeset for docs-only change
@atharv-sys32

atharv-sys32 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @jerelmiller All three changes addressed:

  • Removed changeset
  • "component" -> "library", present tense "warns", "help prevent bugs"
  • "Always use" -> "As a best practice, use"

@atharv-sys32 atharv-sys32 closed this by deleting the head repository Jul 28, 2026
@atharv-sys32

atharv-sys32 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Hey @jsoref! and @jerelmiller I had to close this PR temporarily due to a fork issue, but the changes are still available. I've created a fresh PR with the same fixes at #13365, marking it as draft for now so the more critical bug fix (#13364) can get attention first. All your previous feedback has been incorporated. Appreciate the review!
Btw if you have bandwidth, I would really appreciate if you take a look at #13364 as well. It fixes a real runtime bug where query variable defaults get silently overwritten when undefined is passed explicitly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs should cover links for unique-names anchor

4 participants